<?php
/**
 * (model) 备货预估日志(各类预估)
 */
namespace App\Models\SsBasic;

use Illuminate\Database\Eloquent\Model;
class EstimateLog extends Model
{
    protected $table = 's_area_estimate_log';

    protected $guarded = [];

    //站点
    const TYPE_AREA_ESTIMATE_CLASSIFY = 1; //基础品类预估
    const TYPE_AREA_ESTIMATE_SKU = 2; //基础sku预估
    const TYPE_AREA_ESTIMATE_STOCKING = 3; //备货sku预估

    //站点(国家)
    const TYPE_EU_ESTIMATE_CLASSIFY = 4;
    const TYPE_EU_ESTIMATE_SKU = 5;
    const TYPE_EU_ESTIMATE_STOCKING = 6;

    //JP(平台)
    const TYPE_JP_ESTIMATE_CLASSIFY = 7;
    const TYPE_JP_ESTIMATE_SKU = 8;
    const TYPE_JP_ESTIMATE_STOCKING = 9;

    /**
     * 添加预估日志
     * @param $beforeData
     * @param $afterData
     * @param $type
     * @param array $logData
     */
    public static function addLog($beforeData, $afterData, $type, $logData = []){

        $log = [];

        if (!empty($logData['plat_id'])) {
            $log['plat_id'] = $logData['plat_id'];
        }
        if (!empty($logData['area_id'])) {
            $log['area_id'] = $logData['area_id'];
        }
        if (!empty($logData['country_id'])) {
            $log['country_id'] = $logData['country_id'];
        }
        if (!empty($logData['classify_id'])) {
            $log['classify_id'] = $logData['classify_id'];
        }

        $log['before_data'] = $beforeData;
        $log['after_data'] = $afterData;
        $log['log_type'] = $type;
        $log['log_date'] = date('Y-m-d H:i:s', time());

        EstimateLog::query()->create($log);
    }

}
